#include <iostream>
using namespace std;

int p, ans = 1<<27;
int max_deep = 20;

bool dfs(int x, int y, int deep)
{
	if (deep > max_deep) return false;
	if (x == p || y == p) {
		if (deep < ans) ans = deep;
		return true;
	}
	if (dfs(x, x+y, deep+1) || dfs(x+y, y, deep+1) ||
			dfs(x+x, y, deep+1) || dfs(x, x+x, deep+1) ||
				dfs(y+y, y, deep+1) || dfs(x, y+y, deep+1)) return true;
	if(x > y) {
		if (dfs(x-y, y, deep+1) || dfs(x, x-y, deep+1)) return true;
	}
	if (x < y) {
		if (dfs(y-x, y, deep+1) || dfs(x, y-x, deep+1)) return true;
	}
	if (dfs(0, y, deep+1) || dfs(x, 0, deep+1)) return true;
	return false;
}

int main()
{
	for (int i = 0; i < 100; i++) {
		p = i; ans = 1<<27; max_deep = 20;
		while (dfs(1, 0, 0)) {
			max_deep = ans - 1;
		}
		cout << "p=" << i << ": " << ans << endl;
	}
}
